/**********************************************************************
  The MIT License (MIT)
  Copyright (c) 2012 sunriseyuen

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
  THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ***********************************************************************/

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

#region Using directives
using System;
using System.Text;
using System.IO;
using System.Xml;
using System.Collections;		   
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using System.Web;
using System.Web.UI;

using Muki.Framework;
using Muki.Framework.UI;
using Muki.Framework.Util;
using Muki.Framework.Business;
using Muki.Entity;

using Dot.StreamObject;

#endregion

namespace Muki.UserPanel
{
	public class UID22002AUI : BaseAction
	{
		public UID22002AUI()
		{
		}
		
		public override void OnPreview()
		{
			objUID22002ABB.FileName    = "UID22002A";
			objUID22002ABB.ZZLiveBlock = this.ZZLiveBlock;
			objUID22002ABB.ZZLOGON_ID  = this.ZZLOGON_ID;
			objUID22002ABB.Trans       = this.Trans;
			objUID22002ABB.Process();
			objWebCells.WXFLite     = objUID22002ABB.WXFLite;
			objWebCells.LOGON_LANG  = this.LOGON_LANG;
			objWebCells.CHECKBOX    = false;
			objWebCells.LOGON_CACHE = ZZGeneral.UUID();

			XDataCache oXDataCache  = new XDataCache();
			oXDataCache.LOGON_CACHE = objWebCells.LOGON_CACHE;
			oXDataCache.APP_PATH    = this.APP_PATH;
			oXDataCache.ZZLOGON_ID  = this.ZZLOGON_ID;
			oXDataCache.ZZLiveBlock = this.ZZLiveBlock;
			oXDataCache.UID_CODE    = "UID22002A";
			oXDataCache.IPAddress   = ZZGeneral.IPAddress();
			oXDataCache.CONTEXT     = objUID22002ABB.WXFLite;
			oXDataCache.DbName      = this.DbName;
			oXDataCache.Write();

			objWebCells.LOGON_CACHE=oXDataCache.LOGON_CACHE;

			string PrintableDocument=this.APP_PATH+"cfg\\PrintableDocument.xml";

			if (!File.Exists(PrintableDocument))
			{
				PrintableDocument=this.APP_PATH+"cfg\\PrintableDocument.config";
			}

			//ZZTrace.Error(ZFILE_NAME,PrintableDocument);

			if (File.Exists(PrintableDocument))
			{

				StringBuilder XCodeObject = new StringBuilder(); 

				if (File.Exists(PrintableDocument))
				{
					XCodeObject=ZZGeneral.ReadStream(PrintableDocument);
				}

				VContexts _VContexts=new VContexts(XCodeObject.ToString());

				string DefaultPrintableDocument   = _VContexts.getValue("DefaultPrintableDocument");
				string cExtensions="";
				if (string.IsNullOrEmpty(DefaultPrintableDocument))
				{
					DefaultPrintableDocument="ll";
				}

				string DefaultPrintableExtensions= _VContexts.getValue(DefaultPrintableDocument);

				cExtensions=this.APP_PATH+"System\\Extensions\\"+DefaultPrintableExtensions+".dll";

				//ZZTrace.Error(ZFILE_NAME,cExtensions);

				if (File.Exists(cExtensions))
				{
					System.Reflection.Assembly objAssembly = Dot.StreamObject.Util.ReadAssembly(cExtensions);

					PrintableDocument oPrintableDocument = (PrintableDocument)objAssembly.CreateInstance(DefaultPrintableExtensions);

					string Template=this.APP_PATH+"Layouts\\Default\\UID22002A.lst";


					if (System.IO.File.Exists(Template))
					{
						objWebCells.Wxf_LLViewer=true;
					}

					//ZZTrace.Error(ZFILE_NAME,Template);

					oPrintableDocument.LOGON_LANG=this.LOGON_LANG;
					oPrintableDocument.UID_CODE  ="UID22002A";
					oPrintableDocument.APP_PATH  = this.APP_PATH;
					oPrintableDocument.Trans=Trans;
					oPrintableDocument.Template=Template;
					oPrintableDocument.WXFLite=objUID22002ABB.WXFLite;
					oPrintableDocument.Execute();

					ZZFILE_Url=oPrintableDocument.FileUrl;
					ZZTrace.Error(ZFILE_NAME,ZZFILE_Url);
				}
			}

			if (oXDataCache.LOGON_CACHE!="")
			{
				VContexts oXDepend = new VContexts();

				oXDepend["BUTTON_ID"]     = "btn_"+this.UID_CODE;
				oXDepend["Caption"]       = oZZCaptions.Caption(this.UID_CODE, "lbl_Export_Xls");
				oXDepend["BTN_ATVT_CODE"]   = "javascript";
				oXDepend["STAGEU_STATUS"] = "";
				oXDepend["STATUS_CODE"]   = "";
				oXDepend["XEVENT_CODE"]   = "window.open('../UPl/PrintableDocument.ashx?lnk_DataUrl="+oXDataCache.LOGON_CACHE+"&Txt_UID_CODE="+this.UID_CODE+"&l="+this.LOGON_LANG+"&d="+this.DbName+"&lnk_DefaultPrintableDocument=xls');";
				oXDepend["MESSAGE_ID"]    = "";
				oXDepend["STAGE_CODE"]    = "";
				oXDepend["BTN_HK_CODE"]       = "";
				oXDepend["TITLE_ID"]      = "";
				oXDepend["ICON_CODE"]      = "Xls.gif";

				oXForm.AddXFuns(oXDepend);
			}

			objWebHideBox.Text=objWebCells.LOGON_CACHE;

			oWindow.Java_Script = string.Format(@"llViewer('','UID22002A','{0}');",ZZGeneral.XUrlEncode(ZZFILE_Url));

		}
		
		public override void OnSearch()
		{
			objUID22002ABB.FileName    = "UID22002A";
			objUID22002ABB.ZZLiveBlock = this.ZZLiveBlock;
			objUID22002ABB.ZZLOGON_ID  = this.ZZLOGON_ID;
			objUID22002ABB.Trans       = this.Trans;
			objUID22002ABB.Process();

			objWebCells.WXFLite    = objUID22002ABB.WXFLite;
			objWebCells.LOGON_LANG = this.LOGON_LANG;
			objWebCells.CHECKBOX   = false;

			XDataCache oXDataCache  = new XDataCache();
			oXDataCache.LOGON_CACHE = ZZGeneral.UUID();
			oXDataCache.APP_PATH    = this.APP_PATH;
			oXDataCache.ZZLOGON_ID  = this.ZZLOGON_ID;
			oXDataCache.ZZLiveBlock = this.ZZLiveBlock;
			oXDataCache.DbName      = this.DbName;
			oXDataCache.UID_CODE    = "UID22002A";
			oXDataCache.IPAddress   = ZZGeneral.IPAddress();
			oXDataCache.CONTEXT     = objUID22002ABB.WXFLite;

			ZZTrace.Debug(ZFILE_NAME,objUID22002ABB.WXFLite.RecordCount);

			oXDataCache.Write();

			string Template=this.APP_PATH+"Layouts\\Default\\UID22002A.lst";
			if (this.LOGON_LANG!="")
			{
				if (System.IO.File.Exists(this.APP_PATH+"Layouts\\Default\\"+this.LOGON_LANG+"\\UID22002A.lst"))
				{
					Template=this.APP_PATH+"Layouts\\Default\\"+this.LOGON_LANG+"\\UID22002A.lst";
				}
			}

			if (System.IO.File.Exists(Template))
			{
				objWebCells.Wxf_LLViewer=true;
			}

			if (oXDataCache.LOGON_CACHE!="")
			{
				VContexts oXDepend = new VContexts();

				oXDepend["BUTTON_ID"]     = "btn_"+this.UID_CODE;
				oXDepend["Caption"]       = oZZCaptions.Caption(this.UID_CODE, "lbl_Export_Xls");
				oXDepend["BTN_ATVT_CODE"]   = "javascript";
				oXDepend["STAGEU_STATUS"] = "";
				oXDepend["STATUS_CODE"]   = "";
				oXDepend["XEVENT_CODE"]   = "window.open('../UPl/PrintableDocument.ashx?lnk_DataUrl="+oXDataCache.LOGON_CACHE+"&Txt_UID_CODE="+this.UID_CODE+"&l="+this.LOGON_LANG+"&d=NIX&lnk_DefaultPrintableDocument=xls');";
				oXDepend["MESSAGE_ID"]    = "";
				oXDepend["STAGE_CODE"]    = "";
				oXDepend["BTN_HK_CODE"]       = "";
				oXDepend["TITLE_ID"]      = "";
				oXDepend["ICON_CODE"]      = "Xls.gif";

				oXForm.AddXFuns(oXDepend);
			}

			objWebCells.LOGON_CACHE=oXDataCache.LOGON_CACHE;

			objWebHideBox.Text=oXDataCache.LOGON_CACHE;

		}

		public override void OnCancel()
		{
			string cLOGON_CACHE=objWebHideBox.Text;

			this.ZZVIEW_STATUS_CODE = this.ZZEventStatus;
		}

		public override void Process()
		{
			try
			{
				checked
				{        	
					base.Process();

				}
			}

			catch (LogisticException e)
			{

				MessageInfo oMessageInfo=new MessageInfo();

				oMessageInfo.DbName=this.DbName;
				oMessageInfo.Trans=this.Trans;
				oMessageInfo.ZZLiveBlock=this.ZZLiveBlock;

				//oWindow.MessageBox(oMessageInfo.XMessageInfo("UID22002A",e.Name,e.Logistic,e.Refx));

				ZZTrace.Error(ZFILE_NAME,"<HR>MessageInfo=[" + e.Message + "]" + "<HR>Source=[" + e.Source + "]<HR>StackTrace=[" + e.StackTrace + "]<HR>TargetSite=[" + e.TargetSite + "]");
			}
			catch (Exception e)
			{
				ZZTrace.Error(ZFILE_NAME,"<HR>MessageInfo=[" + e.Message + "]" + "<HR>Source=[" + e.Source + "]<HR>StackTrace=[" + e.StackTrace + "]<HR>TargetSite=[" + e.TargetSite + "]");
			}

		}

		//Framework
		public override void OnInit(HttpContext  objHttpContext)		
		{
			this.UID_CODE = "UID22002A";

			objXStatus.OnInit(objHttpContext);
			objXStatus["ZZXUID_CODE"] = this.UID_CODE;
			objXStatus["ZZUSQL_CODE"]="QID22002A";

			this.ZZLiveBlock   = objXStatus["ZZLiveBlock"];
			this.ZZEventStatus = objXStatus["ZZEventStatus"];
			this.ZZEventArgs   = objXStatus["ZZEventArgs"];
			this.ZZVIEW_STATUS_CODE   = objXStatus["ZZVIEW_STATUS_CODE"];
			this.LOGON_LANG    = objXStatus["LOGON_LANG"];

			this.DbName=ZZGeneral.DbName();
			this.Trans = new StreamContext(this.DbName);

			XLiveManagement oXLiveManagement = XLiveManagement.getInstance();
			oXLiveManagement.DbName=this.DbName;

			if (this.LOGON_LANG=="")
			{
					this.LOGON_LANG=oXLiveManagement[this.ZZLiveBlock].getValue("LOGON_LANG");
					objXStatus["LOGON_LANG"]=this.LOGON_LANG;
			}

			this.ZZLOGON_ID=oXLiveManagement[this.ZZLiveBlock].getValue("LOGON_ID");

			_DocsPermission.ZZLiveBlock = this.ZZLiveBlock;
			_DocsPermission.Trans=this.Trans;

			oZZCaptions             = new ZZCaptions();
			oZZCaptions.ZZLiveBlock = this.ZZLiveBlock;
			oZZCaptions.DbName      = this.DbName;
			oZZCaptions.LOGON_LANG  = this.LOGON_LANG;

			oWindow.ZZLiveBlock   = this.ZZLiveBlock;

			dbTab odbTab       = new dbTab();
			odbTab.ZZLiveBlock = this.ZZLiveBlock;
			odbTab.Trans       = this.Trans;
			odbTab.LOGON_LANG  = this.LOGON_LANG;
			odbTab.UID_CODE    = this.UID_CODE;
			odbTab.Create();

			objWebPanels = odbTab.Panels;
			oWindow.DbName=this.DbName;
			oWindow.AddPanels(objWebPanels);

			if (this.ZZLOGON_ID.Equals(""))
			{
				cAUTH_CODE = 1;
				//oWindow.MessageBox(oZZCaptions.Caption(this.UID_CODE, "lbl_SessionTimeOut"));
			}else if (!oXLiveManagement.CheckValidRequest(this.ZZLiveBlock))
			{
				cAUTH_CODE = 1;
				//oWindow.MessageBox(oZZCaptions.Caption(this.UID_CODE, "lbl_InValidLogin"));
			}else if (_DocsPermission.AccessRight(this.UID_CODE,this.ZZLOGON_ID,"ACCESS")==true)
			{
				oZZCaptions.LoadCaption();

				dbToolbar odbToolbar = new dbToolbar();
				odbToolbar.ZZLiveBlock = this.ZZLiveBlock;
				odbToolbar.LOGON_LANG=this.LOGON_LANG;

					odbToolbar.BTNS_CODE = "QUERY";
				odbToolbar.UID_CODE = this.UID_CODE;
				odbToolbar.Trans    =this.Trans;

				string Template=this.APP_PATH+"Layouts\\Default\\UID22002A.lst";
				if (this.LOGON_LANG!="")
				{
					if (System.IO.File.Exists(this.APP_PATH+"Layouts\\Default\\"+this.LOGON_LANG+"\\UID22002A.lst"))
					{
						Template=this.APP_PATH+"Layouts\\Default\\"+this.LOGON_LANG+"\\UID22002A.lst";
					}
				}

				if (System.IO.File.Exists(Template) &&  !ZZGeneral.IsMobile())
				{
					odbToolbar.ODTP_STATUS_CODE="PRN";
				}else{
					odbToolbar.ODTP_STATUS_CODE="QRY";
				}

				odbToolbar.Process();

				objWebBTNS = odbToolbar.XWebBTNS;
				oWindow.AddToolBar(objWebBTNS);

				oXForm                     = new XForm();
				oXForm.ZZLiveBlock         = objXStatus["ZZLiveBlock"];
				oXForm.Trans               = this.Trans;
				oXForm.UID_CODE            = this.UID_CODE;
				oXForm.LOGON_LANG          = this.LOGON_LANG;
				ZZUSRDefine objZZUSRDefine = new ZZUSRDefine();
				objZZUSRDefine.ZZLiveBlock = this.ZZLiveBlock;

				WebTR     objWebTR=new WebTR();
				WebTD     objWebTD;
				WebCaption objWebCaption;

				XOption objXOption     = new XOption();
				objXOption.ZZLiveBlock = objXStatus["ZZLiveBlock"];
				objXOption.UID_CODE    = this.UID_CODE;
				objXOption.Trans       = this.Trans;
				objXOption.LOGON_LANG  = this.LOGON_LANG;
				objXOption.All_Opt     = true;

				XOption oXOption     = new XOption();
				oXOption.ZZLiveBlock = this.ZZLiveBlock;
				oXOption.UID_CODE    = this.UID_CODE;
				oXOption.Trans       = this.Trans;
				oXOption.LOGON_LANG  = this.LOGON_LANG;

				if (ZZGeneral.XRequest("lnk_FILE_Viewer")=="Y")
				{
					FILE_Viewer=true;
				}else{
					FILE_Viewer=false;
				}

				QueryRows RsZUPRGDTM = new QueryRows(this.Trans);

				RsZUPRGDTM.CommandText = "SELECT * FROM ZUPRGDTM WHERE UID_CODE = '" + this.UID_CODE + "' AND ACTIVE_BIT<>0 ORDER BY ORDINAL";
				RsZUPRGDTM.Open();
				int ORDINAL=10000;
				while (!RsZUPRGDTM.EOF)
				{
					string cTABLE_NAME            = RsZUPRGDTM.getValue("TABLE_NAME");
					string cCOLUMN_NAME           = RsZUPRGDTM.getValue("COLUMN_NAME");
					string cSTAGEU_STATUS         = RsZUPRGDTM.getValue("STAGEU_STATUS");
					string cCOLUMN_NAME_B         = RsZUPRGDTM.getValue("BASE_COLUMN_NAME");
					string cTABLE_NAME_B          = RsZUPRGDTM.getValue("BASE_TABLE_NAME");
					string cCOLUMN_CLASS_CODE     = RsZUPRGDTM.getValue("COLUMN_CLASS_CODE");
					string cCOLUMN_TP_CODE        = RsZUPRGDTM.getValue("COLUMN_TP_CODE");
					string cDATA_VIEWER           = RsZUPRGDTM.getValue("DATA_VIEWER");
					string cUGET_XREF             = RsZUPRGDTM.getValue("RELY_DEFAULT");
					string cUGET_VIEW             = RsZUPRGDTM.getValue("RELY_VIEW");
					string cXOPT_CODE             = RsZUPRGDTM.getValue("OPT_CODE");
					bool bCOLUMN_NULLABLE         = !RsZUPRGDTM.getBoolean("COLUMN_NULLABLE");
					bool cLINE_REVEAL             = RsZUPRGDTM.getBoolean("LINE_REVEAL");
					bool cNewLine                 = RsZUPRGDTM.getBoolean("NEW_LINE");
					string cLABEL_ID              = RsZUPRGDTM.getValue("LABEL_ID");
					int    cCOLSPAN               = RsZUPRGDTM.getInteger("COLS_SPAN");
					int    cROWSPAN               = RsZUPRGDTM.getInteger("ROWS_SPAN");
					int    cCOLUMN_HEIGHT         = RsZUPRGDTM.getInteger("COLUMN_HEIGHT");
					int    cCOLUMN_SCALE         = 0;
					string TABLE_NAME_COLUMN_NAME = cTABLE_NAME + "_" + cCOLUMN_NAME;

					string _COLUMN=this.DbName+"_COLUMN_"+TABLE_NAME_COLUMN_NAME;
					if (oData.ContainsKey(_COLUMN))
					{
						VContexts _ZUCOLUTM=oData[_COLUMN];
						cCOLUMN_TP_CODE = _ZUCOLUTM.getValue("COLUMN_TP_CODE");
						cCOLUMN_SCALE  = _ZUCOLUTM.getInteger("COLUMN_SCALE");
					}else{
						QueryRows RsZUCOLUTM = new QueryRows(this.Trans);

						VContexts _ZUCOLUTM = new VContexts();
						RsZUCOLUTM.CommandText = "SELECT COLUMN_TP_CODE,COLUMN_SCALE FROM ZUCOLUTM WHERE TABLE_NAME = '" + cTABLE_NAME + "' AND COLUMN_NAME='" + cCOLUMN_NAME + "'";
						RsZUCOLUTM.Open();
						if (!RsZUCOLUTM.EOF)
						{
							_ZUCOLUTM["COLUMN_TP_CODE"]      = RsZUCOLUTM.getValue("COLUMN_TP_CODE");
							_ZUCOLUTM["COLUMN_SCALE"]       = RsZUCOLUTM.getInteger("COLUMN_SCALE");

						}else{
							_ZUCOLUTM["COLUMN_TP_CODE"]      = cCOLUMN_TP_CODE;
							_ZUCOLUTM["COLUMN_SCALE"]       = 0;
						}
						RsZUCOLUTM.Close();
						oData[_COLUMN]=_ZUCOLUTM;
						cCOLUMN_TP_CODE = _ZUCOLUTM.getValue("COLUMN_TP_CODE");
						cCOLUMN_SCALE  = _ZUCOLUTM.getInteger("COLUMN_SCALE");
					}

					if (cCOLUMN_TP_CODE == "decimal" && cCOLUMN_CLASS_CODE!="")
					{
						QueryRows RsZTCLASSM = new QueryRows(this.Trans);
						RsZTCLASSM.CommandText = "SELECT COLUMN_SCALE FROM ZTCLASSM WHERE COLUMN_CLASS_CODE = '" + cCOLUMN_CLASS_CODE + "'";
						RsZTCLASSM.Open();
						if (!RsZTCLASSM.EOF)
						{
							cCOLUMN_SCALE = RsZTCLASSM.getInteger("COLUMN_SCALE");
						}
						RsZTCLASSM.Close();
					}

					if (cCOLUMN_TP_CODE=="datetime")
					{

						WebDateBox oTABLE_NAME_COLUMN_NAME    = new WebDateBox();

						oTABLE_NAME_COLUMN_NAME.Name          = "Txt_" + TABLE_NAME_COLUMN_NAME+"_FM";
						oTABLE_NAME_COLUMN_NAME.Length        = 40;
						oTABLE_NAME_COLUMN_NAME.Height        = cCOLUMN_HEIGHT;
						oTABLE_NAME_COLUMN_NAME.COLUMN_SCALE = cCOLUMN_SCALE;
						oTABLE_NAME_COLUMN_NAME.STATUS_CODE   = cSTAGEU_STATUS;
						oTABLE_NAME_COLUMN_NAME.Compulsory    = bCOLUMN_NULLABLE;
						oTABLE_NAME_COLUMN_NAME.Caption       = oZZCaptions.Caption(this.UID_CODE, cLABEL_ID);
						oTABLE_NAME_COLUMN_NAME.COLSPAN       = cCOLSPAN;
						oTABLE_NAME_COLUMN_NAME.ROWSPAN       = cROWSPAN;
						oTABLE_NAME_COLUMN_NAME.NEW_LINE      = cNewLine;
						oTABLE_NAME_COLUMN_NAME.NEW_CELL      = true;
						oTABLE_NAME_COLUMN_NAME.LINE_REVEAL   = cLINE_REVEAL;
						oTABLE_NAME_COLUMN_NAME.Index         = ORDINAL++;

						oXForm.AddObject(oTABLE_NAME_COLUMN_NAME);
						if (cTABLE_NAME!="VARIABLE")
						{
							oTABLE_NAME_COLUMN_NAME    = new WebDateBox();

							oTABLE_NAME_COLUMN_NAME.Name          = "Txt_" + TABLE_NAME_COLUMN_NAME+"_TO";
							oTABLE_NAME_COLUMN_NAME.Length        = 40;
							oTABLE_NAME_COLUMN_NAME.Height        = cCOLUMN_HEIGHT;
							oTABLE_NAME_COLUMN_NAME.COLUMN_SCALE = cCOLUMN_SCALE;
							oTABLE_NAME_COLUMN_NAME.STATUS_CODE   = cSTAGEU_STATUS;
							oTABLE_NAME_COLUMN_NAME.Compulsory    = bCOLUMN_NULLABLE;
							oTABLE_NAME_COLUMN_NAME.Caption       = oZZCaptions.Caption(this.UID_CODE, cLABEL_ID);
							oTABLE_NAME_COLUMN_NAME.COLSPAN       = cCOLSPAN;
							oTABLE_NAME_COLUMN_NAME.ROWSPAN       = cROWSPAN;
							oTABLE_NAME_COLUMN_NAME.NEW_LINE      = false;
							oTABLE_NAME_COLUMN_NAME.NEW_CELL      = true;
							oTABLE_NAME_COLUMN_NAME.LINE_REVEAL   = cLINE_REVEAL;
							oTABLE_NAME_COLUMN_NAME.Index         = ORDINAL++;

							oXForm.AddObject(oTABLE_NAME_COLUMN_NAME);
						}					

					}else if (cCOLUMN_TP_CODE=="decimal")
					{

						WebDigitBox oTABLE_NAME_COLUMN_NAME    = new WebDigitBox();

						oTABLE_NAME_COLUMN_NAME.Name          = "Txt_" + TABLE_NAME_COLUMN_NAME;
						oTABLE_NAME_COLUMN_NAME.Length        = 8;
						oTABLE_NAME_COLUMN_NAME.Height        = cCOLUMN_HEIGHT;
						oTABLE_NAME_COLUMN_NAME.COLUMN_SCALE = cCOLUMN_SCALE;
						oTABLE_NAME_COLUMN_NAME.STATUS_CODE   = cSTAGEU_STATUS;
						oTABLE_NAME_COLUMN_NAME.Compulsory    = bCOLUMN_NULLABLE;
						oTABLE_NAME_COLUMN_NAME.Caption       = oZZCaptions.Caption(this.UID_CODE, cLABEL_ID);
						oTABLE_NAME_COLUMN_NAME.COLSPAN       = cCOLSPAN;
						oTABLE_NAME_COLUMN_NAME.ROWSPAN       = cROWSPAN;
						oTABLE_NAME_COLUMN_NAME.NEW_LINE      = cNewLine;
						oTABLE_NAME_COLUMN_NAME.NEW_CELL      = true;
						oTABLE_NAME_COLUMN_NAME.LINE_REVEAL   = cLINE_REVEAL;
						oTABLE_NAME_COLUMN_NAME.Index         = ORDINAL++;

						oXForm.AddObject(oTABLE_NAME_COLUMN_NAME);

					}else if (cCOLUMN_TP_CODE=="boolean")
					{

						WebCheckBox oTABLE_NAME_COLUMN_NAME    = new WebCheckBox();

						oTABLE_NAME_COLUMN_NAME.Name          = "Txt_" + TABLE_NAME_COLUMN_NAME;
						oTABLE_NAME_COLUMN_NAME.Length        = 8;
						oTABLE_NAME_COLUMN_NAME.Height        = cCOLUMN_HEIGHT;
						oTABLE_NAME_COLUMN_NAME.STATUS_CODE   = cSTAGEU_STATUS;
						oTABLE_NAME_COLUMN_NAME.Compulsory    = bCOLUMN_NULLABLE;
						oTABLE_NAME_COLUMN_NAME.Caption       = oZZCaptions.Caption(this.UID_CODE, cLABEL_ID);
						oTABLE_NAME_COLUMN_NAME.COLSPAN       = cCOLSPAN;
						oTABLE_NAME_COLUMN_NAME.ROWSPAN       = cROWSPAN;
						oTABLE_NAME_COLUMN_NAME.NEW_LINE      = cNewLine;
						oTABLE_NAME_COLUMN_NAME.NEW_CELL      = true;
						oTABLE_NAME_COLUMN_NAME.LINE_REVEAL   = cLINE_REVEAL;
						oTABLE_NAME_COLUMN_NAME.Index         = ORDINAL++;

						oXForm.AddObject(oTABLE_NAME_COLUMN_NAME);

					}else{
						if (cXOPT_CODE!="")
						{
							WebOption oTABLE_NAME_COLUMN_NAME    = new WebOption();

							oTABLE_NAME_COLUMN_NAME.Name          = "Txt_" + TABLE_NAME_COLUMN_NAME;
							oTABLE_NAME_COLUMN_NAME.Length        = 40;
							oTABLE_NAME_COLUMN_NAME.Height        = cCOLUMN_HEIGHT;
							oTABLE_NAME_COLUMN_NAME.COLUMN_SCALE = cCOLUMN_SCALE;
							oTABLE_NAME_COLUMN_NAME.STATUS_CODE   = cSTAGEU_STATUS;
							oTABLE_NAME_COLUMN_NAME.Compulsory    = bCOLUMN_NULLABLE;
							oTABLE_NAME_COLUMN_NAME.Caption       = oZZCaptions.Caption(this.UID_CODE, cLABEL_ID);
							oTABLE_NAME_COLUMN_NAME.COLSPAN       = 4;
							oTABLE_NAME_COLUMN_NAME.ROWSPAN       = cROWSPAN;
							oTABLE_NAME_COLUMN_NAME.NEW_LINE      = cNewLine;
							oTABLE_NAME_COLUMN_NAME.NEW_CELL      = true;
							oTABLE_NAME_COLUMN_NAME.LINE_REVEAL   = cLINE_REVEAL;
							oTABLE_NAME_COLUMN_NAME.Index         = ORDINAL++;

							oXOption.OPT_CODE=cXOPT_CODE;
							oXOption.Process();
							oTABLE_NAME_COLUMN_NAME.Option       =oXOption.Option;

							oXForm.AddObject(oTABLE_NAME_COLUMN_NAME);

						}else{
							WebTextBox oTABLE_NAME_COLUMN_NAME   = new WebTextBox();

							oTABLE_NAME_COLUMN_NAME.Name          = "Txt_" + TABLE_NAME_COLUMN_NAME;
							oTABLE_NAME_COLUMN_NAME.Length        = 40;
							oTABLE_NAME_COLUMN_NAME.Height        = cCOLUMN_HEIGHT;
							oTABLE_NAME_COLUMN_NAME.COLUMN_SCALE = cCOLUMN_SCALE;
							oTABLE_NAME_COLUMN_NAME.STATUS_CODE   = cSTAGEU_STATUS;
							oTABLE_NAME_COLUMN_NAME.Compulsory    = bCOLUMN_NULLABLE;
							oTABLE_NAME_COLUMN_NAME.Caption       = oZZCaptions.Caption(this.UID_CODE, cLABEL_ID);
							oTABLE_NAME_COLUMN_NAME.COLSPAN       = 4;
							oTABLE_NAME_COLUMN_NAME.ROWSPAN       = cROWSPAN;
							oTABLE_NAME_COLUMN_NAME.NEW_LINE      = cNewLine;
							oTABLE_NAME_COLUMN_NAME.NEW_CELL      = true;
							oTABLE_NAME_COLUMN_NAME.LINE_REVEAL   = cLINE_REVEAL;
							oTABLE_NAME_COLUMN_NAME.Index         = ORDINAL++;

							if (cUGET_XREF!="")
							{

								WebBrowser oTABLE_NAME_COLUMN_NAMEBrw =new WebBrowser();

								oTABLE_NAME_COLUMN_NAMEBrw.UGET_CODE    =cUGET_XREF;
								oTABLE_NAME_COLUMN_NAMEBrw.Data_Viewer  =cDATA_VIEWER;

								oTABLE_NAME_COLUMN_NAMEBrw.ACTIVE_FIELD =cTABLE_NAME_B+"."+cCOLUMN_NAME_B;

								oTABLE_NAME_COLUMN_NAME.Browser         =oTABLE_NAME_COLUMN_NAMEBrw;
							}

							if (cUGET_VIEW!="")
							{
								oTABLE_NAME_COLUMN_NAME.OnBlurEvents="RefreshData('"+cUGET_VIEW+"','VIEW','Txt_"+TABLE_NAME_COLUMN_NAME+"');";
							}else if (cUGET_XREF!="")
							{
								oTABLE_NAME_COLUMN_NAME.OnBlurEvents="RefreshData('"+cUGET_XREF+"','XREF','Txt_"+TABLE_NAME_COLUMN_NAME+"');";

								oTABLE_NAME_COLUMN_NAME.UGET_CODE=cUGET_XREF;
							}
							oXForm.AddObject(oTABLE_NAME_COLUMN_NAME);
						}
					}
					RsZUPRGDTM.MoveNext();  
				}

#region XUID_CODE
				objPARTBLM_XUID_CODE.Name    = "Txt_PARTBLM_XUID_CODE";
				objPARTBLM_XUID_CODE.Caption = oZZCaptions.Caption(this.UID_CODE,"lbl_XUID_CODE");
				objPARTBLM_XUID_CODE.Text    = "UID22002A";
				oXForm.AuthObject(objPARTBLM_XUID_CODE);
#endregion

				objWebHideBox.Name = "lnk_DataUrl";
				oXForm.AddObject(objWebHideBox);

				objWebCells.Name          = "QID22002A";
				objWebCells.PickUp        = false;
				objWebCells.Trans         = this.Trans;
				objWebCells.ZZLiveBlock   = this.ZZLiveBlock;
				objWebCells.AsyncWxfPage  = false;
				objWebCells.OperationMode = "ReadOnly";
				objWebCells.PageSize      = 20;
				objWebCells.DbName        = this.DbName;
				objWebCells.LOGON_LANG    = this.LOGON_LANG;

				oWindow.AddWxfPanel(objWebCells);

				oWindow.AddWebForm(oXForm);

			} else
			{
				//oWindow.MessageBox(oZZCaptions.Caption(this.UID_CODE, "lbl_AccessRight"));
			}

			oWindow.OnInit(objHttpContext);
			_Initialize(objHttpContext);
		}

		private void _Initialize(HttpContext  objHttpContext)		
		{

				if (ZZGeneral.XRequest("lnk_PARTBLM_ITEM_NO")!="")
				{
					ZZTrace.Debug(ZFILE_NAME,"lnk_PARTBLM_ITEM_NO=["+ZZGeneral.XRequest("lnk_PARTBLM_ITEM_NO")+"]");
					objPARTBLM_ITEM_NO.Text=ZZGeneral.XRequest("lnk_PARTBLM_ITEM_NO");
				}


		}

		public override void Render(HtmlTextWriter objTextWriter)
		{

			bool ZZFILE_VIEW=false;
			ZZTrace.Debug(ZFILE_NAME,ZZFILE_Url);
			if (ZZFILE_Url!="")
			{
				ZZTrace.Debug(ZFILE_NAME,ZZFILE_Url);

				if (System.IO.File.Exists(ZZFILE_Url))
				{
				
					ZZFILE_VIEW=true;
				}
			}

			if (FILE_Viewer && ZZFILE_VIEW)
			{
				objTextWriter.WriteLine("<html>");
				objTextWriter.WriteLine("<head>");
				objTextWriter.WriteLine("</head>");
				objTextWriter.WriteLine("<body bgcolor=#F3F6FC topmargin=0 leftmargin=2 marginwidth=0 marginheight=0 border=0 onload='javascript:ZZXWindow();'>");
				objTextWriter.WriteLine("<form name=frmGlobal method=post id=frmGlobal>");
				objTextWriter.WriteLine("</form>");
				oWebDocViewer.FileUrl="PrintableDocument.ashx?lnk_DataUrl="+objWebHideBox.Text+"&Txt_UID_CODE=UID22002A&Txt_FileURL="+ZZGeneral.XUrlEncode(ZZFILE_Url)+"&Txt_LOGON_LANG="+this.LOGON_LANG;
				oWebDocViewer.Render(objTextWriter);
				objTextWriter.WriteLine("</body>");
				objTextWriter.WriteLine("</html>");

			}else{

				objWebCells.ZZLiveBlock=this.ZZLiveBlock;
				oWindow.Trans      = this.Trans;
				oWindow.VIEW_STATUS_CODE = this.ZZVIEW_STATUS_CODE;
				objXStatus["ZZVIEW_STATUS_CODE"] = this.ZZVIEW_STATUS_CODE;

				objWebCells.STATUS_CODE ="VIEW";
				objWebCells.VIEW_STATUS_CODE   =this.ZZVIEW_STATUS_CODE;
				objWebCells.LOGON_LANG=this.LOGON_LANG;

				objWebCells.Process();

				objWebCells.AsyncWxfPage=false;

				oWindow.WindowsStatus = objXStatus;
				oWindow.UID_CODE      = "UID22002A";
				oWindow.LOGON_LANG    = this.LOGON_LANG;
				oWindow.APP_PATH      = this.APP_PATH;
				oWindow.Template      = "";

				oWindow.Render(objTextWriter);

				StringBuilder cCodeBlock = new StringBuilder();

				StringWriter oCodeBlock = new StringWriter(cCodeBlock);

				objXStatus.CodeBlock(oCodeBlock);
				oWindow.CodeBlock(oCodeBlock);

			}
		}

		const string ZFILE_NAME = "UID22002AUI";

		private XForm oXForm;
		private WebPanels objWebPanels;
		private ZZCaptions oZZCaptions;
		private XStatus objXStatus               = new XStatus();
		private WebCells objWebCells             = new WebCells();
		private ZZDocsPermission _DocsPermission = new ZZDocsPermission();
		private Window oWindow                   = new Window();
		private WebBTNS objWebBTNS               = new WebBTNS();
		private WebDocViewer oWebDocViewer       = new WebDocViewer();
		private bool   FILE_Viewer               = false;
		private string ZZFILE_Url                = "";
		private int cAUTH_CODE                   = 0;
#region screen element
		private WebHideBox objWebHideBox         = new WebHideBox();
		protected WebCaption objPARTBLM_XUID_CODE       =new WebCaption();

					private WebTextBox objPARTBLM_ITEM_NO =new WebTextBox();
    private WebBrowser objPARTBLM_ITEM_NOBrw =new WebBrowser();


		private UID22002ABB   objUID22002ABB           = new UID22002ABB();
		private static Dictionary<string, VContexts> oData = new Dictionary<string, VContexts>();
#endregion
	}
}
